package com.wuhan.template.module.find.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.find.bean.MeishiBean;
import com.wuhan.template.module.find.webview.WebViewActivity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/12.
 */
public class MeishiListAdapter extends MyBaseAdapter<MeishiBean.ListBean> {

    private DisplayImageOptions options;
    private List<MeishiBean.ListBean> list;
    private Context mContext;

    public MeishiListAdapter(Context context, List<MeishiBean.ListBean> list) {
        super(context, list);
        this.list = list;
        this.mContext = context;
        options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_meishi_layout;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new MyBaseViewHolder();
    }


    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {

        final MyBaseViewHolder holder = (MyBaseViewHolder) viewHolder;

        final MeishiBean.ListBean.ChildsDataBean indexpic = list.get(holder.position).getChilds_data().get(0);

        String picUrl = indexpic.getHost() + indexpic.getDir() + indexpic.getFilepath() + indexpic.getFilename();

        holder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("url", list.get(holder.position).getContent_url());
                intent.putExtra("title", "美食");
                mContext.startActivity(intent);
            }
        });

        ((BaseApplication) mContext.getApplicationContext()).getImageLoader().displayImage(picUrl, holder.imageView, options);
        String commentNum = list.get(holder.position).getComment_num();

        String title = list.get(holder.position).getTitle();


        holder.tvPinglun.setText("评论 : " + commentNum);
        holder.tvTitle.setText(title);

    }

    class MyBaseViewHolder extends BaseViewHolder {

        @BindView(R.id.ms_tupian)
        ImageView imageView;
        @BindView(R.id.ms_title)
        TextView tvTitle;
        @BindView(R.id.ms_pinglun)
        TextView tvPinglun;

    }
}
